package com.cjq.auth.controller;

import com.cjq.auth.service.AuthService;
import com.cjq.common.domain.User;
import com.cjq.common.domain.request.UserReq;
import com.cjq.common.domain.response.UserRes;
import com.cjq.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthController {
    @Autowired
    private AuthService authService;

    /**
     * 账号密码登录
     * @param userReq
     * @return
     */
    @PostMapping("/accountLogin")
    public Result<UserRes> accountLogin(@RequestBody UserReq userReq){
        UserRes userRes = authService.accountLogin(userReq);
        return Result.success(userRes);
    }

    /**
     * 获取登录人信息
     * @return
     */
    @GetMapping("/user/info")
    public Result<User> userInfo(){
        User user = authService.userInfo();
        return Result.success(user);
    }

    /**
     * 退出登录
     */
    @PostMapping("/logout")
    public Result logout(){
        authService.logout();
        return Result.success();
    }
}
